package com.nm.orm.pojo;

import com.nm.orm.pojo.inter.IEntityTime;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.Set;

/**
 * Created by hewu on 2017/2/7 0007.
 */
@Entity
@Table(name = "article", catalog = "soft")
public class ArticleEntity implements IEntityTime, Serializable {

    /**
     * serializable
     */
    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "id")
    @GeneratedValue(generator = "UUIDGenerate", strategy = GenerationType.IDENTITY)
    @GenericGenerator(name = "UUIDGenerate", strategy = "uuid")
    private String id;

    @Column(name = "name")
    private String name;

    @Column(name = "content")
    private String content;

    @Column(name = "created_at")
    private Date createdAt;

    @Column(name = "updated_at")
    @UpdateTimestamp
    private Date updatedAt;

    @Column(name = "hit")
    private Integer hit;

    @Column(name = "state")
    private int state;

    @JoinColumn(name = "userId")
    @ManyToOne(fetch = FetchType.EAGER)
    private UserEntity user;

    @JoinColumn(name = "categoryId")
    @ManyToOne(fetch = FetchType.EAGER)
    private CategoryEntity category;

    @OneToMany(fetch = FetchType.LAZY,cascade = CascadeType.ALL,mappedBy = "article")
    private Set<ArticleLabelRefEntity> artLabelRefs;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public void setUser(UserEntity user) {
        this.user = user;
    }

    public void setCategory(CategoryEntity category) {
        this.category = category;
    }

    public UserEntity getUser() {
        return user;
    }

    public Set<ArticleLabelRefEntity> getArtLabelRefs() {
        return artLabelRefs;
    }

    public CategoryEntity getCategory() {
        return category;
    }

    public Date getCreatedAt() {
        return createdAt;
    }

    @Override
    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    @Override
    public Date getUpdatedAt() {
        return updatedAt;
    }

    @Override
    @UpdateTimestamp
    public void setUpdatedAt(Date updatedAt) {
        this.updatedAt = updatedAt;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public Integer getHit() {
        return hit;
    }

    public void setHit(Integer hit) {
        this.hit = hit;
    }

    public void setArtLabelRefs(Set<ArticleLabelRefEntity> artLabelRefs) {
        this.artLabelRefs = artLabelRefs;
    }

}
